﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Model;
using MsDAL;
using System.ComponentModel;
using Components;

namespace ServiceHelper
{
    [DataObjectAttribute]
    public partial class Tic3a00Manager : Tic3a00Base
    {
        private static Tic3a00Manager _entity;

        public static Tic3a00Manager Entity
        {
            get
            {
                if (_entity == null)
                    _entity = new Tic3a00Manager();
                return _entity;
            }
        }

        public string SaveData(Hashtable tb, DataTable dtl, DataTable deldata, string action, string usercode)
        {
            List<SqlApp> lst = new List<SqlApp>();

            Tic3a00 model = null;
            Tic3a01 dtlModel = null;


            string appstr = Context.GetAppByUserCode(usercode);

            if ("K" == action) //开票
            {
                //保存概要表身
                model = new Tic3a00();
                Components.CommonUtil.GetInstance.CopyProperties(tb, model);

                model.Listid = Sys0a60Manager.Entity.CreateSn("tic3000c_listid", usercode);
                model.Usercode = appstr;
                lst.Add(this.Add(model));

                foreach (DataRow dr in dtl.Rows)
                {
                    dtlModel = new Tic3a01();
                    dtlModel.Listid = Sys0a60Manager.Entity.CreateSn("tic3a01_listid", usercode);
                    dtlModel.Orderid = Validation.ToString(dr["listid"]); //订单标识
                    dtlModel.Plistid = model.Listid;

                    lst.Add(Tic3a01Manager.Entity.Add(dtlModel));

                    //更新订单状态为已经开票
                    lst.Add(Ord3a00Manager.Entity.AlreadyTackTicket(dtlModel.Orderid));
                }

                //写一笔应收帐款
                Tic4a00 tic4a00 = new Tic4a00();
                Components.CommonUtil.GetInstance.CopyProperties(model, tic4a00, true, true);
                tic4a00.Listid = Sys0a60Manager.Entity.CreateSn("tic4a00_listid", usercode);

                lst.Add(Tic4a00Manager.Entity.Add(tic4a00));
            }

            return CommonManager.Entity.SaveData(lst);
        }
    }
}



